package com.qf.agro.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.agro.common.ResultInfo;
import com.qf.agro.pojo.Crop;
import com.qf.agro.service.CropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/crop/crop")
public class CropController {
    @Autowired
    private CropService cropService;
    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize, String name) {
        Page<Crop> page =cropService.findPage(pageNum,pageSize,name);
        return ResultInfo.success(page);
    }
    @PostMapping
    public ResultInfo save(@RequestBody Crop crop){
        cropService.save(crop);
        return ResultInfo.success(null);
    }
    @PutMapping
    public ResultInfo update(@RequestBody Crop crop){
        cropService.update(crop);
        return ResultInfo.success(null);
    }
    @DeleteMapping
    public ResultInfo delete(Long id){
        cropService.delete(id);
        return ResultInfo.success(null);
    }
}
